package Date;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author chihb
 * @create-time 2024/7/4 10:20
 * @description
 */
public class demo2 {
    public static void main(String[] args) {
        // 输入年份和月份
        int year = 2023; // 示例年份
        int month = 2; // 示例月份

        // 首次休息日
        LocalDate firstRestDay = LocalDate.of(2020, 2, 1);

        // 计算间隔天数
        long daysBetween = LocalDate.of(year, month, 1).toEpochDay() - firstRestDay.toEpochDay();

        // 找出休息日
        List<LocalDate> restDays = new ArrayList<>();
        for (int i = 0; i < daysBetween; i++) {
            LocalDate day = firstRestDay.plusDays(i);
            if (day.getDayOfWeek() == DayOfWeek.SATURDAY) {
                restDays.add(day);
            }
        }

        // 筛选出属于输入月份的休息日
        long daysInMonth = LocalDate.of(year, month, 1).lengthOfMonth();
        long daysInRestPeriod = daysBetween - daysInMonth;
        for (int i = 0; i < daysInRestPeriod; i++) {
            LocalDate day = restDays.get(i);
            if (day.getMonthValue() == month) {
                restDays.add(day);
            }
        }

        // 输出结果
        System.out.println("休息日总数: " + restDays.size());
        System.out.println("本月休息日天数: " + restDays.stream().filter(d -> d.getMonthValue() == month).count());
        System.out.println("轮到周末休息的天数: " + restDays.stream().filter(d -> d.getDayOfWeek() == DayOfWeek.SATURDAY).count());
    }
}